<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@include file="/sunzbase.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>

<title>修改密码 - 会员管理 -</title>
<meta name="keywords" content="天遥笔记">
<meta name="description" content="天遥">
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-change-password">
		<input type="hidden" name="id" id="id" value="${userPwd.id}">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>账户：</label>
			<div class="formControls col-xs-8 col-sm-9"> ${userPwd.username }</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>旧密码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="password" class="input-text" autocomplete="off" placeholder="请输入旧密码" name="oldPwd" id="oldPwd">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>新密码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="password" class="input-text" autocomplete="off" placeholder="请输入新密码" name="newPwd" id="newPwd">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="password" class="input-text" autocomplete="off" placeholder="确认密码" name="newpassword2" id="newpassword2">
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存&nbsp;&nbsp;" id="updatePasswordForm">
				<input class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;恢复初始密码&nbsp;&nbsp;" id="resetPassword">
			</div>
		</div>
	</form>
</article>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="http://cdn.bootcss.com/jquery/2.1.3/jquery.min.js"></script> 
<script type="text/javascript" src="resources/static/h-ui/js/H-ui.js"></script> 
<script type="text/javascript" src="resources/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="resources/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="resources/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="resources/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function(){
	$("#form-change-password").validate({
		rules:{
			oldPwd:{
				required:true,
			},
			newPwd:{
				required:true,
				isPwd:true
			},
			newpassword2:{
				required:true,
				isPwd:true,
				equalTo: "#newPwd"
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				url:"${webRoot}/note/changePassword",
				data:$("#form-change-password").serialize(),
				type:"POST",
				dataType:"json",
				success:function(result){
					if(result.success){
						layer.msg(result.msg,{icon:1});
						setTimeout(function(){
							window.parent.location.reload();
						}, 2000);
					}else{
						layer.alert(result.msg,{icon:2});
					}
				}
			});
		}
	});
});
$("#resetPassword").on('click',function(){
	layer.prompt({title: '输入管理员密码，并确认', formType: 1}, function(pass, index){
		  $.ajax({
				type: 'POST',
				url: '${webRoot}/note/confirmAdminPassword',
				data:"password="+pass,
				dataType: 'json',
				success: function(data){
					if(data.success){
						layer.msg(data.msg,{icon: 6,time:1000});
						setTimeout(function(){
							resetUserPassword();
						},1000);
					}else{
						layer.msg(data.msg,{icon: 2,time:1000});
					}
				}
			});
		});
})
function resetUserPassword(){
	layer.confirm('确认重置密码?',function(index){
		$.ajax({
			type: 'POST',
			url: '${webRoot}/note/resetPassword',
			data:"id="+$("#id").val(),
			dataType: 'json',
			success: function(result){
				if(result.success){
					layer.msg(result.msg,{icon: 6,time:1000});
					setTimeout(function(){
						layer_close();
					},1700);
				}
			}
		});
	});
}
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>